package com.bridgeintelligent.tag.scene.controller;

import com.bridgeintelligent.tag.scene.api.ISceneCatalogService;
import com.bridgeintelligent.tag.scene.api.dto.SceneDto;
import com.bridgeintelligent.tag.scene.api.entity.SceneCatalog;
import com.bridgeintelligent.tag.scene.api.vo.SceneVO;
import com.bridgeintelligent.tag.webserver.dim.mgmt.api.vo.IndexDimCatalogVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotBlank;
import java.util.List;
import java.util.Map;

/**
 * @description
 * @author: grp 2021-01-07 11:15
 **/
@Api(tags = "场景目录")
@RestController
@AllArgsConstructor
@RequestMapping("api/sceneCatalog")
@Validated
public class SceneCatalogController {

    private ISceneCatalogService sceneCatalogService;
    @ApiOperation(value = "目录加载", notes = "场景目录管理")
    @GetMapping("list")
    public SceneDto<Object> list() {
        List<SceneCatalog> result = sceneCatalogService.list();
        return SceneDto.success().setData(result);
    }

    @ApiOperation(value = "首页-目录加载-一级目录", notes = "场景目录管理")
    @GetMapping("parentList")
    public SceneDto<List<SceneCatalog>> parentList() {
        List<SceneCatalog> result = sceneCatalogService.parentList();
        return SceneDto.success(result);
    }

    @ApiOperation(value = "首页-目录加载-场景列表", notes = "场景目录管理")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "type", value = "类型", required = false)})
    @GetMapping("scenes")
    public SceneDto<Map<String, List<SceneVO>>> scenes(String type) {
        Map<String, List<SceneVO>> result = sceneCatalogService.scenes(type);
        return SceneDto.success(result);
    }

    @ApiOperation(value = "目录加载-场景列表", notes = "场景目录管理")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "id", value = "目录id", required = true)})
    @GetMapping("sceneList")
    public SceneDto<List<SceneVO>> sceneList(String id) {
        List<SceneVO> result = sceneCatalogService.sceneList(id);
        return SceneDto.success(result);
    }

    @ApiOperation(value = "新增场景目录", notes = "场景目录管理")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "parentId", value = "目录上级目录ID，一级目录传入-", required = true), @ApiImplicitParam(paramType = "query", name = "name", value = "目录名称", required = true), @ApiImplicitParam(paramType = "query", name = "number", value = "排序编号", required = true)})
    @PostMapping("add")
    public SceneDto<Object> add(String parentId, String name, Integer number) {
        return sceneCatalogService.add(parentId, name, number);
    }

    @ApiOperation(value = "目录切换", notes = "场景目录管理")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "id", value = "目录ID", required = true), @ApiImplicitParam(paramType = "query", name = "parentId", value = "目录上级目录ID"), @ApiImplicitParam(paramType = "query", name = "name", value = "目录名称"), @ApiImplicitParam(paramType = "query", name = "number", value = "排序编号")})
    @PostMapping("update")
    public SceneDto<Object> update(String id, String parentId, String name, Integer number) {
        sceneCatalogService.update(id, parentId, name, number);
        return SceneDto.success();
    }

    @ApiOperation(value = "场景目录删除", notes = "场景目录管理")
    @ApiImplicitParams({@ApiImplicitParam(paramType = "query", name = "id", value = "目录ID", required = true)})
    @DeleteMapping("del")
    public SceneDto<Object> del(@NotBlank String id) {
        return sceneCatalogService.del(id);
    }
}
